package com.broada.apm.utils;

import com.broada.apm.ApmServer;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 创建一个固定大小的同步队列
 */
public class FixSizeBlockingQueueUtils {
    public static <T> BlockingQueue<T> create(int max_size) {
        return new LinkedBlockingDeque<T>((int) (max_size * 1.05)) {
            @Override
            public boolean add(T t) {
                while (size()>=max_size) {
                    remove();
                }
                return super.add(t);
            }
        };
    }
}
